package leetcode.simple._previous;


import java.util.HashMap;
import java.util.Map;

//得到一个链表中倒数第k个节点
public class KthFromEnd {

    public ListNode getKthFromEnd(ListNode head, int k) {
        Map<Integer,ListNode> map = new HashMap<>();

        int index = 1;
        ListNode node = head;
        while (node != null) {
            map.put(index++,node);
            node = node.next;
        }

        return map.get(index - k);
    }

}
